package com.dragonboat.controller;
import com.dragonboat.entity.Event;

import com.dragonboat.service.CommonService;
import com.dragonboat.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/common")
public class CommonController {
    @Autowired
    private CommonService commonService;

    @GetMapping("/events")
    public ResponseResult<List<Event>> getAllEvents() {
        return ResponseResult.success(commonService.getAllEvents());
    }



    @GetMapping("/event/{eventId}")
    public ResponseResult<Event> getEventDetails(@PathVariable Integer eventId) {
        return commonService.getEventById(eventId)
                .map(ResponseResult::success)
                .orElse(ResponseResult.error("Event not found"));
    }
}